﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BSC;
using EmrDatastructure;
using System.Reflection;

namespace EmrDevTests
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnTestingExceptions_Click(object sender, EventArgs e)
        {
            try
            {
                EmrDemographic emrDemographic = new EmrDemographic();
                emrDemographic.Id = "SeedTest";

                IEmrService _service = GetService();
                _service.CreateEmrDemographic(emrDemographic);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                if (ex.InnerException != null)
                {
                    MessageBox.Show(ex.InnerException.Message);
                }
            }
        }
        private IEmrService GetService()
        {
            return DALFactory.DataAccess.CreateDataAccessLayer();   
            bool useWcf = true;
            if (useWcf)
            {
                return (IEmrService)Assembly.Load("WcfEmrDAL").CreateInstance("WcfEmrDAL.EmrService"); 
                return new WcfEmrDAL.EmrService();
            }
            else
            {
                return (IEmrService)Assembly.Load("EmrDAL").CreateInstance("EmrDAL.EmrService");
                return new EmrDAL.EmrService();
            }
        }

        private void btnReadDemographic_Click(object sender, EventArgs e)
        {
            try
            {
                IEmrService _service = GetService();
                 EmrDemographic emrDemographic  = _service.ReadEmrDemographic("SeedTest");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                if (ex.InnerException != null)
                {
                    MessageBox.Show(ex.InnerException.Message);
                }
            }
        }

        private void btnlogger1_Click(object sender, EventArgs e)
        {
            string s = string.Format("{0} {1} {3} {4}", 1, 2, 3, 4);
            EmrLogger.Logger.Log(EmrLogger.LogLevel.Warn, "hello", null, "{0} {1}", 1, 2);
        }
    }
}
/*
EmrDemographic emrDemographic = new EmrDemographic();
            emrDemographic.Id = "SeedTest";
            emrDemographic.PreferredLanguage = "1";
            emrDemographic.Gender = "2";
            emrDemographic.Race = "3";
            emrDemographic.Ethnicity = "4";
            emrDemographic.DateOfBirth = new DateTime(1970, 5, 6);
            emrDemographic.FirstName = "7";
            emrDemographic.LastName = "8";

            IEmrService _service = new EmrRepository();

            _service.DeleteEmrDemographic("SeedTest");

            _service.CreateEmrDemographic(emrDemographic);
            
            EmrDemographic emrDemographicRead = _service.ReadEmrDemographic("SeedTest");

            emrDemographicRead.Gender = "22";
            _service.UpdateEmrDemographic(emrDemographicRead);

            _service.DeleteEmrDemographic("SeedTest");
 
 * 
 * 
 
 */